
Component({
    /**
     * 组件的属性列表
     */
    properties: {
        pageNum: {
            type: Number,
            value: 0
        },
        pageSize: {
            type: Number,
            value: 10
        },
        totalPage: {
            type: Number,
            value: 0
        },
        isEmpty: {
            type: Number,
            value: 0
        },
        emptyImg: {
            type: String,
            value: ''
        },
        isNoneLoading: {
            type: Boolean,
            value: true
        },
        scrollHeight: {
            type: String,
            value: '100%'
        },
        background: {
            type: String,
            value: ''
        },
        type: {
            type: String,
            value: 'default'
        },
        refreshStyle: {
            type: String,
            value: 'black'
        },
        refreshBackground: {
            type: String,
            value: '#f2f2f2'
        },
        refreshthreshold: {
            type: Number,
            value: 45
        },
        refreshBackgroundImage: {
            type: String,
            value: ''
        },
        refreshColor: {
            type: String,
            value: '#999999'
        },
        refreshTitleShow: {
            type: Boolean,
            value: true
        },
        refreshDiy: {
            type: Boolean,
            value: false
        }
    },
    /**
     * 组件的初始数据
     */
    data: {
        isRefreshLoading: true,
        triggered: false,
        threshold: 0,
        upTitle: '下拉可以刷新',
        scrollTop: 0,
        scrollType: 'refresh' // refresh 和 loadMore 两种模式
    },
    lifetimes: {
        // 生命周期函数，可以为函数，或一个在methods段中定义的方法名
        attached: function () { 
            //console.log(this.data.page)
            
        },
        ready: function () {
            // if(this.data.isEmpty%10!=0){
            //     this.setData({
            //         isNoneLoading: true
            //     })
            // }
            //console.log(this.data.page)
        },
        moved: function () { 
            //console.log("moved")
        },
        detached: function () { 
            //console.log("detached")
        },
    },
    
    /**
     * 组件的方法列表
     */
    methods: {
        onPulling: function () {
            this.setData({
                isRefreshLoading: true,
            });
        },
        onRefresh() {
            this.setData({
                upTitle: "正在刷新..."
            });
            setTimeout(() => {
                this.setData({
                    triggered: false,
                });
            }, 1000);
        },
        onRestore(e) {
            this.triggerEvent("refresh", {
                pageNum: this.data.pageNum,
            });
            this.setData({
                isRefreshLoading: false,
                upTitle: '下拉可以刷新',
                threshold: 0
            });
        },
        onPullingDiy: function (evt) {
            var p = Math.min(evt.detail.dy / 80, 1);
            this.triggerEvent("refreshPulling", {
                p: p
            });
            let upTitle = '';
            if (p < 0.5) {
                upTitle = '下拉可以刷新';
            } else {
                upTitle = '释放立即刷新';
            }
            // console.log(p)
            this.setData({
                isRefreshLoading: true,
                threshold: p,
                upTitle: upTitle
            });
        },
        lower: function (e) {
             console.log(e)
            if (this.data.pageNum <= this.data.totalPage&&this.data.isNoneLoading) {
                this.triggerEvent("loadMore");
                // if(this.data.page == this.data.totalPage){
                    
                // }
            }
        },
        scroll: function (e) {
            // console.log(e.detail.scrollTop)
            this.triggerEvent("scrolling", {
                scrollTop: e.detail.scrollTop
            });
        }
    }
})